﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XMK.Framework.Model;
using XMK.Tadong.Data;
using XMK.Utils;
using XMK.Tadong.Model;
using XMK.Tadong.Model.Cond;
using System.Data;

namespace XMK.Tadong.Biz
{
   public  class EXTBiz
    {
       /// <summary>
       /// 根据文件扩展名获取文件格式
       /// </summary>
       /// <param name="extent"></param>
       /// <returns></returns>
       public ExtTypeinfo getExtCodeByExtent(string extent)
       {
           try
           {
               EXTData data = new EXTData(Config.TadongDbProvider);
               return (ExtTypeinfo)data.getExtCodeByExtent(extent.ToLower());
           }
           catch (Exception ex)
           {
               LogHelper.WriteLog(LogType.Error, "[EditDictType:]" + ex.ToString());
           }
           return null;
       }
       /// <summary>
       /// 根据格式值获取图标路径
       /// </summary>
       /// <param name="extent"></param>
       /// <returns></returns>
       public ExtTypeinfo getExtCodeByType(string fileType)
       {
           try
           {
               EXTData data = new EXTData(Config.TadongDbProvider);
               return (ExtTypeinfo)data.getExtCodeByType(fileType);
           }
           catch (Exception ex)
           {
               LogHelper.WriteLog(LogType.Error, "[EditDictType:]" + ex.ToString());
           }
           return null;
       }
       /// <summary>
       /// 根据格式id获取文件格式
       /// </summary>
       /// <param name="extent"></param>
       /// <returns></returns>
       public ExtTypeinfo getExtCodeByExtId(decimal ext_id)
       {
           try
           {
               EXTData data = new EXTData(Config.TadongDbProvider);
               return (ExtTypeinfo)data.getExtCodeByExtId(ext_id);
           }
           catch (Exception ex)
           {
               LogHelper.WriteLog(LogType.Error, "[EditDictType:]" + ex.ToString());
           }
           return null;
       }

       /// <summary>
       /// 格式类型列表
       /// </summary>
       /// <returns></returns>
       public ResponseInfo QueryExtTypeList(PageInfo pageInfo, OrderInfo order)
       {
           ResponseInfo response = null;
           try
           {
               EXTData data = new EXTData(Config.TadongDbProvider);
               response = new ResponseInfo();
               response.Data = (List<ExtTypeinfo>)data.QueryExtTypeList(pageInfo, order);
               response.Page = pageInfo;
           }
           catch (Exception ex)
           {
               //生成返回对象（带错误信息）
               response = new ResponseInfo("error！");
               LogHelper.WriteLog(LogType.Error, "[QueryExtTypeList:]" + ex.ToString());
           }
           return response;

       }
       /// <summary>
       /// 类型编辑
       /// </summary>
       /// <param name="cond"></param>
       /// <returns></returns>
       public ResponseInfo EditExtType(Base_ExtTypeCond cond)
       {
           ResponseInfo response = null;
           try
           {
               
               EXTData data = new EXTData(Config.TadongDbProvider);
               response = new ResponseInfo();
               response.Data = (bool)data.EditExtType(cond);
               if (response.Data != null)
               {
                   response.Data = true;
               }
               else
               {
                   response.Data = (bool)data.EditExtType(cond);
               }
           }
           catch (Exception ex)
           {
               //生成返回对象（带错误信息）
               response = new ResponseInfo("error！");
               LogHelper.WriteLog(LogType.Error, "[EditDictType:]" + ex.ToString());
           }
           return response;

       }
       /// <summary>
       /// 获取扩展名列表
       /// </summary>
       /// <param name="DICTTYPE_ID"></param>
       /// <param name="pageInfo"></param>
       /// <param name="order"></param>
       /// <returns></returns>
       public ResponseInfo QueryExtItemList(decimal EXT_ID, PageInfo pageInfo, OrderInfo order)
       {
           ResponseInfo response = null;
           try
           {
               EXTData data = new EXTData(Config.TadongDbProvider);
               response = new ResponseInfo();
               response.Data = (List<Base_ExtItemCond>)data.QueryExtItemList(EXT_ID, pageInfo, order);
               response.Page = pageInfo;
           }
           catch (Exception ex)
           {
               //生成返回对象（带错误信息）
               response = new ResponseInfo("error！");
               LogHelper.WriteLog(LogType.Error, "[QueryDictItemList:]" + ex.ToString());
           }
           return response;

       }
       /// <summary>
       /// 删除扩展名元素
       /// </summary>
       /// <param name="cond"></param>
       /// <returns></returns>
       public ResponseInfo EditExtItem(Base_ExtItemCond cond)
       {
           ResponseInfo response = null;
           try
           {
               EXTData data = new EXTData(Config.TadongDbProvider);
               response = new ResponseInfo();
               response.Data = (bool)data.EditExtItem(cond);
           }
           catch (Exception ex)
           {
               //生成返回对象（带错误信息）
               response = new ResponseInfo("error！");
               LogHelper.WriteLog(LogType.Error, "[EditExtItem:]" + ex.ToString());
           }
           return response;

       }
       /// <summary>
       /// 新增文件格式
       /// </summary>
       /// <param name="cond"></param>
       /// <returns></returns>
       public ResponseInfo ExtTypeAdd(ExtTypeinfo cond)
       {
           ResponseInfo response = null;
           try
           {
               EXTData data = new EXTData(Config.TadongDbProvider);
               response = new ResponseInfo();
               ExtTypeinfo exttyoe = data.getExtCodeByType(cond.EXT_CODE);
               if (exttyoe == null)
               {
                   response.Data = (bool)data.ExtTypeAdd(cond);
               }
               else
               {
                   response.Data = false;
               }
             
              
             
           }
           catch (Exception ex)
           {
               //生成返回对象（带错误信息）
               response = new ResponseInfo("error！");
               LogHelper.WriteLog(LogType.Error, "[ExtTypeAdd:]" + ex.ToString());
           }
           return response;

       }
       /// <summary>
       /// 编辑文件格式
       /// </summary>
       /// <param name="cond"></param>
       /// <returns></returns>
       public ResponseInfo ExtTypeEdit(ExtTypeinfo cond)
       {
           ResponseInfo response = null;
           try
           {

               EXTData data = new EXTData(Config.TadongDbProvider);
               response = new ResponseInfo();

               response.Data = (bool)data.UpdateExtType(cond);
           }
           catch (Exception ex)
           {
               //生成返回对象（带错误信息）
               response = new ResponseInfo("error！");
               LogHelper.WriteLog(LogType.Error, "[ExtTypeAdd:]" + ex.ToString());
           }
           return response;

       }
       /// <summary>
       /// 根据类型id获取类型数据
       /// </summary>
       /// <param name="ext_id"></param>
       /// <returns></returns>
       public ResponseInfo InnitExtType(decimal ext_id)
       {
           ResponseInfo response = new ResponseInfo();
           EXTData data = new EXTData(Config.TadongDbProvider);
           response.Data = (ExtTypeinfo)data.getExtCodeByExtId(ext_id);
           return response;
       }

       /// <summary>
       /// 获取扩展名列表
       /// </summary>
       public DataTable QueryExtList()
       {
            EXTData data = new EXTData(Config.TadongDbProvider);
            return  data.QueryExtIList();
       }
      
    }
}
